log using "log_replication_psrm_ppp_SectionsB_C.log", replace

*****Additional analysis for Platforms, Portfolios, Policy: How Audience Costs Affect Social Welfare Policy in Multiparty Cabinets 
******By Despina Alexiadou, University of Strathclyde and Danial Hoepfner, University of Pittsburgh***


***load data
use "PSRM_Alexiadou_votechcombined2_stata13.dta", clear

*****Replicating supporting evidence. Section B of the Appendix*****
*********************************voting*************
******Replication of TABLE 2A**************************************
**Testing effects for election-country****
*****RESULT:The left's pledge affects vote intention depending on changes in welfare generosity across the models. Yet, for voters who voted left in last elections
*****the control of the portfolio of social affairs strongly predicts their vote intention***********

*********************************************************************************************
********************************All voters****************************************************
**********************************************************************************************

************Intercating Left Pledge*Change in Welfare Generosity*Left Governmnet**************
meqrlogit vleftt dtotgen leftpled leftgov leftaff genxgov pledxgov pledxgenxgov pledxgen age female educ inc lr unem union B1008 ||ccode:
estimates store gov
eststo avgov
*************Intercating Left Pledge*Change in Welfare Generosity*Left Social Affairs**********
meqrlogit vleftt dtotgen leftpled leftgov leftaff pledxgen pledxsa genxaff genxleftpledxsa age female educ inc lr unem union B1008 ||ccode:
estimates store sa
eststo avsa
******************************************************************************************************
*******************************Only voters who voted left in the previous election********************
******************************************************************************************************
************Intercating Left Pledge*Change in Welfare Generosity*Left Governmnet
meqrlogit vleftt dtotgen leftpled leftgov leftaff genxgov pledxgov pledxgenxgov pledxgen age female educ inc lr unem union B1008 ||ccode: if vlefttm1==1
estimates store govtm1
eststo lvgov
*************Intercating Left Pledge*Change in Welfare Generosity*Left Social Affairs**********
meqrlogit vleftt dtotgen leftpled leftgov leftaff pledxgen pledxsa genxaff genxleftpledxsa age female educ inc lr unem union B1008 ||ccode: if vlefttm1==1
estimates store satm1
eststo lvsa

esttab avgov avsa lvgov lvsa, label order(dtotgen leftpled leftgov leftaff pledxgen genxgov pledxgov pledxgenxgov pledxsa genxaff genxleftpledxsa age female educ inc lr unem union B1008)

*****Predicted probabilities: calculations for discussion on pages 10 & 11 of the Online Appendix
sum dtotgen leftpled  
di 8.85+6.0
di -.24-.75
di 14.85*-.99

******All voters*****

estimates restore gov

**high pledge low gen w/ gov
margins, at(leftgov=1 dtotgen=-.99 leftpled=14.85 leftaff=0 pledxgen=-14.7 pledxgov=14.85 genxgov=-.99 pledxgenxgov=-14.7) atmeans predict(mu fixedonly)
**high pledge low gen w/0 gov
margins, at(leftgov=0 dtotgen=-.99 leftpled=14.85 leftaff=0 pledxgen=-14.7 pledxgov=0 genxgov=0 pledxgenxgov=0) atmeans predict(mu fixedonly)


estimates restore sa

**high pledge low gen w/ sa
margins, at(leftgov=1 dtotgen=-.99 leftpled=14.85 leftaff=1 pledxgen=-14.7 pledxsa=14.85 genxaff=-.99 genxleftpledxsa=-14.7) atmeans predict(mu fixedonly)
**high pledge low gen w/0 sa
margins, at(leftgov=1 dtotgen=-.99 leftpled=14.85 leftaff=0 pledxgen=-14.7 pledxsa=0 genxaff=0 genxleftpledxsa=0) atmeans predict(mu fixedonly)


****Only left voters***

estimates restore govtm1
**high pledge low gen w/ gov
margins, at(leftgov=1 dtotgen=-.99 leftpled=14.85 leftaff=0 pledxgen=-14.7 pledxgov=14.85 genxgov=-.89 pledxgenxgov=-14.7) atmeans predict(mu fixedonly)
**high pledge low gen w/0 gov
margins, at(leftgov=0 dtotgen=-.99 leftpled=14.85 leftaff=0 pledxgen=-14.7 pledxgov=0 genxgov=0 pledxgenxgov=0) atmeans predict(mu fixedonly)

estimates restore satm1
**high pledge low gen w/ sa
margins, at(leftgov=1 dtotgen=-.99 leftpled=14.85 leftaff=1 pledxgen=-14.7 pledxsa=14.85 genxaff=-.99 genxleftpledxsa=-14.7) atmeans predict(mu fixedonly)
**high pledge low gen w/0 sa
margins, at(leftgov=1 dtotgen=-.99 leftpled=14.85 leftaff=0 pledxgen=-14.7 pledxsa=0 genxaff=0 genxleftpledxsa=0) atmeans predict(mu fixedonly)

***
*****Replicating supporting evidence. Section C of the Appendix*****
***Deriving the expected utility values of making strong pledges pre-electorally. Discussion on Pages 12 & 13 of the online Appendix

** vote diff for 1 sd change in pledge across mean, for range of totgen HOLD SA: here we predict the potential electoral losses if strong pledge, welfare cuts & control of social affairs portfolio (about 4.5%)
meqrlogit vleftt dtotgen leftpled leftgov leftaff pledxgen pledxsa genxaff genxleftpledxsa age female educ inc lr unem union B1008 ||ccode:
matrix SA = (.,.)
forvalues p = -2(.2).8  {
di 9.06+4.98
***11.5 low
***16.5 high
di `p'
local lplxg=`p'*9.06
local hplxg=`p'*14
di `p'
margins, at(leftgov=1 dtotgen=`p' leftpled=9.06 leftaff=1 pledxgen=`lplxg' pledxsa=9.06 genxaff=`p' genxleftpledxsa=`lplxg') atmeans predict(mu fixedonly)
matrix list r(b)
matrix l=r(b)
matrix list l
margins, at(leftgov=1 dtotgen=`p' leftpled=14 leftaff=1 pledxgen=`hplxg' pledxsa=14 genxaff=`p' genxleftpledxsa=`hplxg') atmeans predict(mu fixedonly)
matrix list r(b)
matrix h=r(b)
di "HERE!"
matrix dif=h-l
matrix list dif
matrix dif2=dif,`p'
matrix list dif2
matrix SA=SA\dif2
matrix list SA
}
*svmat SA
sum SA1 SA2
scatter SA1 SA2
*gen percvoteSA=SA1*100
label variable percvoteSA "Vote Change in SA"
label variable SA2 "D.Totgen"
twoway (line percvoteSA SA2),yline(0) title(Expected Vote Cost at Time of Negotiation) 

** vote diff for 1 sd change in pledge across mean, for range of totgen in GOV: Here we predict the potential electoral losses/gains if the left makes a strong pledge & does not control social affairs (about 3.3%)
matrix GP = (.,.)
forvalues p = .1(.1)1.5 {
di `p'
local lpl=9.06-`p'*4.98*.5
local hpl=9.06+`p'*4.98*.5
local lplxg=`lpl'*-.7	
local hplxg=`hpl'*-.7
di `p'
margins, at(leftgov=1 dtotgen=-.7 leftpled=`lpl' leftaff=0 pledxgen=`lplxg' pledxsa=0 genxaff=0 genxleftpledxsa=0) atmeans predict(mu fixedonly)
matrix list r(b)
matrix l=r(b)
matrix list l
margins, at(leftgov=1 dtotgen=-.7 leftpled=`hpl' leftaff=0 pledxgen=`hplxg' pledxsa=0 genxaff=0 genxleftpledxsa=0) atmeans predict(mu fixedonly)
matrix list r(b)
matrix h=r(b)
di "HERE!"
matrix dif=h-l
matrix list dif
matrix dif2=dif,`p'
matrix list dif2
matrix GP=GP\dif2
matrix list GP
}
*svmat GP
sum GP1 GP2
*gen percvoteGP=GP1*100
label variable percvoteGP "Vote Change in SA"
label variable GP2 "Pledge Size Shift"
twoway (line percvoteGP GP2),yline(0) title(Expected Vote Cost at Time of Negotiation)

** vote diff for 1 sd change in pledge across mean, for range of totgen OUT of GOV: Here we predict the potential electoral losses/gains if the left makes a strong pledge & stays out of government (about 3.5%)
matrix NG = (.,.)
forvalues p = -2(.2).8  {
***5.8 low
***11.895 high
di `p'
local lplxg=`p'*9.06
local hplxg=`p'*14
di `p'
margins, at(leftgov=0 dtotgen=`p' leftpled=9.06 leftaff=1 pledxgen=`lplxg' pledxsa=0 genxaff=0 genxleftpledxsa=0) atmeans predict(mu fixedonly)
matrix list r(b)
matrix l=r(b)
matrix list l
margins, at(leftgov=0 dtotgen=`p' leftpled=14 leftaff=1 pledxgen=`hplxg' pledxsa=0 genxaff=0 genxleftpledxsa=0) atmeans predict(mu fixedonly)
matrix list r(b)
matrix h=r(b)
di "HERE!"
matrix dif=h-l
matrix list dif
matrix dif2=dif,`p'
matrix list dif2
matrix NG=NG\dif2
matrix list NG
}
*svmat NG
sum NG1 NG2
*gen percvoteNG=NG1*100
label variable percvoteNG "Vote Change High-Low Pledge"
label variable NG2 "D.Totgen"
twoway (line percvoteNG SA2),yline(0) title(Expected Vote Cost at Time of Negotiation) 

***Equation 4 of Section C in the Online Appendix: Page 13****
*gen preexpvote=(.69*.75*percvoteSA)+.69*(1-.75)*percvoteG+(1-.69)*percvoteNG
label variable preexpvote "Vote Change Pre Election"
twoway (line percvoteSA SA2)(line preexpvote SA2),yline(0) title(Expected Vote Cost +/-1/2 SD Around Mean)


***** Figure CA1****
  # delimit; 
graph twoway hist dtotgen, yscale(alt off noline) fcolor(gs15) lwidth(vvvthin) // yscale provides options about the axis for this plot
		  || line percvoteSA SA2, clpattern(solid) clwidth(thin) yaxis(2) yscale(alt axis(2)) //Add as many overlaying plots as you like as new lines 
		  || line preexpvote SA2, clpattern(solid) clwidth(thick) yaxis(2) yscale(alt axis(2)) //Add as many overlaying plots as you like as new lines 
		  ||,
             xscale(noline)
             yscale(noline)
             legend(order(2 3))
             title("Expected Vote Cost/Benefit", size(5))
             subtitle("Range of Welfare Spending, 1 SD Change in Pledge", size(4))
             xtitle("Welfare", size(3))
             ytitle("Vote Cost/Benefit", size (3) axis(2)) 
             ytitle("") 
             note("", size(2))
             xsca(titlegap(2))
             ysca(titlegap(4))
             scheme(s2mono)
             graphregion(fcolor(white))
             graphregion(margin(zero));
 # delimit cr            exit; //Changes end line back to normal

graph export GraphCA1_ppp.tif, replace width(4800)
graph export GraphCA1_ppp.pdf, replace 

****Preparing data for Figure CA2***
** vote diff for 1 sd change in pledge across mean, for range of totgen: Here we estimate the expected electoral loss/gain, holding the cuts in welfare constant at -.7 and varying the stenght of the left pledge, when not in governmnet
matrix NGP = (.,.)
forvalues p = .1(.1)1.5 {
***mean totgen -.238
***5.8 low
***11.895 high
**** sd 6.09
di `p'
local lpl=9.06-`p'*4.98*.5
local hpl=9.06+`p'*4.98*.5
local lplxg=`lpl'*-.7	
local hplxg=`hpl'*-.7
di `p'
margins, at(leftgov=0 dtotgen=-.7 leftpled=`lpl' leftaff=0 pledxgen=`lplxg' pledxsa=0 genxaff=0 genxleftpledxsa=0) atmeans predict(mu fixedonly)
matrix list r(b)
matrix l=r(b)
matrix list l
margins, at(leftgov=0 dtotgen=-.7 leftpled=`hpl' leftaff=0 pledxgen=`hplxg' pledxsa=0 genxaff=0 genxleftpledxsa=0) atmeans predict(mu fixedonly)
matrix list r(b)
matrix h=r(b)
di "HERE!"
matrix dif=h-l
matrix list dif
matrix dif2=dif,`p'
matrix list dif2
matrix NGP=NGP\dif2
matrix list NGP
}
*svmat NGP
sum NGP1 NGP2
*gen percvoteNGP=NGP1*100
label variable percvoteNGP "Vote Change in SA"
label variable NGP2 "Pledge Size Shift"
twoway (line percvoteNGP GP2),yline(0) title(Expected Vote Cost at Time of Negotiation)

*gen preexpvoteP=(.69*.74*percvoteSAP)+.69*(1-.74)*percvoteGP+(1-.69)*percvoteNGP
label variable preexpvoteP "Vote Change Pre Election"
twoway (line percvoteSAP SAP2)(line preexpvoteP SAP2),yline(0) title(Expected Vote Cost +/-1/2 SD Around Mean)

sum leftpled
*gen stanleft=leftpled/r(sd)

***** Figure CA2

sum leftpled
*gen stanleft=leftpled/r(sd)

 # delimit; 
	graph twoway hist stanleft if stanleft>0&stanleft<1.5, yscale(alt off noline) fcolor(gs15) lwidth(vvvthin) // yscale provides options about the axis for this plot
		  || line percvoteSAP SAP2, clpattern(solid) clwidth(thin) yaxis(2) yscale(alt axis(2)) //Add as many overlaying plots as you like as new lines 
		  || line preexpvoteP SAP2, clpattern(solid) clwidth(thick) yaxis(2) yscale(alt axis(2)) //Add as many overlaying plots as you like as new lines 
		  ||,
             xscale(noline)
             yscale(noline)
             legend(order(2 3))
             title("Expected Vote Cost/Benefit", size(5))
             subtitle("Range of Pledges, 1 SD Lower Generosity", size(4))
             xtitle("Standardized Pledge", size(3))
             ytitle("Cost/Benefit", size (3) axis(2)) 
             ytitle("") 
             note("", size(2))
             xsca(titlegap(2))
             ysca(titlegap(4))
             scheme(s2mono)
             graphregion(fcolor(white))
             graphregion(margin(zero));
 # delimit cr            exit; //Changes end line back to normal

graph export GraphCA2_ppp.tif, replace width(4800)
graph export GraphCA2_ppp.pdf, replace 

log close
